grammar CVFPG;

options {
language = Java;
}

@header {
package org.ru.mse10.cvfpg;
}

@lexer::header {
package org.ru.mse10.cvfpg;
}


format
  : 'format' IDENT ';'
    pages  
    usePage
  ;
  
pages
  : 'pages' page+ 'end'
  ;

page
  : 'page' IDENT ':'
      'orientation' ('landscape' | 'portrait')
      'margins' DECIMAL DECIMAL DECIMAL DECIMAL
    'end'
  ;
  
usePage
  : 'use' IDENT
    block
  ;

block
  : 'block'
      (text | inline | list | table | block)*
    'end'
  ;
  

inline
  : 'inline'
      (text | inline | block | table)*
    'end'
  ;
  
list
  : 'list'
      listItem+
    'end'
  ;
  
listItem
  : 'item'
      (text | block | table | list)*
    'end'
  ;
  
table
  : 'table'
      tableHeader?
      tableRow+
    'end'
  ;
  
tableHeader
  : 'header'
      tableRow
    'end'
  ;
  
tableRow
  : 'row'
      tableCell+
    'end'
  ;
  
tableCell
  : 'cell'
      (text | block | table | list)+
    'end'
  ;
  
text
  : 'text' .* 'end'
  ;
  

IDENT: ('a'..'z' | 'A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9' | '-' | '_')+;
INTEGER: ('0' | ('1'..'9' ('0'..'9'))*);
DECIMAL: ('0' | ('1'..'9' ('0'..'9')*))('.' ('0'..'9')+)?;
WHITESPACE: (' ' | '\t' | '\f' | '\n')+ {$channel=HIDDEN;};
SINGLE_LINE_COMMENT: '//' (~('\n'|'\r'))* ('\n'|'\r'('\n')?)? {$channel=HIDDEN;};
MULTI_LINE_COMMENT: '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;};